package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.AskLeave;
import com.ruoyi.system.domain.RepairDetail;
import com.ruoyi.system.mapper.RepairDetailMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.RepairMapper;
import com.ruoyi.system.domain.Repair;
import com.ruoyi.system.service.IRepairService;

/**
 * 维修管理表Service业务层处理
 *
 * @author ruoyi
 * @date 2023-11-03
 */
@Service
public class RepairServiceImpl implements IRepairService
{
    @Autowired
    private RepairMapper repairMapper;

    @Autowired
    private RepairDetailMapper repairDetailMapper;
    /**
     * 查询维修管理表
     *
     * @param id 维修管理表主键
     * @return 维修管理表
     */
    @Override
    public Repair selectRepairById(Long id)
    {
        List<RepairDetail> repairDetails = repairDetailMapper.selectRepairDetailByRepairId(id);
        System.out.println("查询维修的id："+id);
        Repair repair = repairMapper.selectRepairById(id);
        repair.setRepairDetailList(repairDetails);
        return repair;
    }

    /**
     * 查询维修管理表列表
     *
     * @param repair 维修管理表
     * @return 维修管理表
     */
    @Override
    public List<Repair> selectRepairList(Repair repair)
    {
        return repairMapper.selectRepairList(repair);
    }

    /**
     * 新增维修管理表
     *
     * @param repair 维修管理表
     * @return 结果
     */
    @Override
    public int insertRepair(Repair repair)
    {
        return repairMapper.insertRepair(repair);
    }

    /**
     * 修改维修管理表
     *
     * @param repair 维修管理表
     * @return 结果
     */
    @Override
    public int updateRepair(Repair repair)
    {
        return repairMapper.updateRepair(repair);
    }

    /**
     * 批量删除维修管理表
     *
     * @param ids 需要删除的维修管理表主键
     * @return 结果
     */
    @Override
    public int deleteRepairByIds(Long[] ids)
    {
        return repairMapper.deleteRepairByIds(ids);
    }

    /**
     * 删除维修管理表信息
     *
     * @param id 维修管理表主键
     * @return 结果
     */
    @Override
    public int deleteRepairById(Long id)
    {
        return repairMapper.deleteRepairById(id);
    }

    //查询所有待审批状态
    @Override
    public List<Repair> selectListByStatus(Long index) {
        Repair repair = new Repair();
        repair.setStatus(index.toString());
        List<Repair> repairs = repairMapper.selectRepairList(repair);
        for (Repair repair1 : repairs) {
            List<RepairDetail> repairDetails = repairDetailMapper.selectRepairDetailByRepairId(repair1.getId());
            repair1.setRepairDetailList(repairDetails);
        }
        return repairs;
    }
}
